<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
  String path = request.getContextPath();
%>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆页面</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<%-- http-equiv --%>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, must-revalidate">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="keywords" content="kms">
<meta http-equiv="description" content="kms web">

<link rel="stylesheet" type="text/css" href="<%=path %>/css/normalize.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/css/main.css">
<style>
  body {
    background: url('<%=path %>/images/fzu.jpg') fixed center;
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
</style>
</head>
<body>

<aticle class="login">
  <form id="loginform" class="form-horizontal" action="<%=path %>/servlet/admin/AdminLoginServlet" method="post">
    <input type="hidden" id="md5password" name="md5password" value=""/>

    <div class="form-group text-muted text-center">
      <h2>欢迎使用</h2>
      <h3>福州大学正版软件管理平台</h3>
      <br/>
    </div>

    <div class="form-group">
      <label for="adminname" class="col-sm-3 control-label">用户名</label>
      <div class="col-sm-9">
        <input type="text" class="form-control" id="adminname" name="adminname"
               placeholder="管理员账号" autocomplete="off" value="admin1" />
      </div>
    </div>

    <div class="form-group">
      <label for="password" class="col-sm-3 control-label">密码</label>
      <div class="col-sm-9">
        <input type="password" class="form-control" id="password" name="password"
                placeholder="密码" autocomplete="off" value="123qwe"/>
      </div>
    </div>

    <div class="form-group">
      <label for="checkcode" class="col-sm-3 control-label">验证码</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="checkcode" name="checkcode"
               placeholder="验证码" autocomplete="off"/>
      </div>
      <div class="col-xs-4 col-sm-5">
        <div id="code" style=""></div>
      </div>
    </div>

    <div class="form-group">
      <div class="col-sm-offset-3 col-sm-6">
        <button id="loginsubmit" type="button" class="btn btn-primary btn-block" href="javascript:void 0;">
          &nbsp;&nbsp;&nbsp;登&nbsp;&nbsp;&nbsp;陆&nbsp;&nbsp;&nbsp;
        </button>
      </div>
    </div>
  </form>
</aticle>

<!-- data-main指加载完js文件后立刻加载的文件 -->
<script type="text/javascript" src="<%=path %>/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/require.js"></script>
<script type="text/javascript" src="<%=path %>/bootstrap/js/bootstrap.min.js"></script>
<script>
require.config({
  baseUrl: '<%=path %>/js',
  paths: {
    jquery: 'jquery-1.9.1.min',
    commmon: 'common',
    md5: 'md5',
    yzm: 'gVerify'
  }
});

require(['jquery', 'common', 'md5', 'yzm'], function ($, common, md5) {
  $(function () {
    // console.log("登陆页面载入");

    /*取得dom对象*/
    var $loginBtn = $("#loginsubmit");
    var $loginForm = $("#loginform");

    /*初始化验证器*/
    var verifyCode = new GVerify({ id: "code", type: "number" });

    /*登陆动作*/
    $loginBtn.on("click", function () {// 点击登陆》表单提交
      common.disable($loginBtn);

      if (($("#adminname").val().length === 0) || ($("#checkcode").val().length === 0) || ($("#password").val().length === 0)) {// 未填写值不允许提交
        alert("请填写所有登陆信息");
        common.enable($loginBtn);
      } else {
        if (!verifyCode.validate($("#checkcode").val())) {
          alert("验证码错误");
          $("#checkcode").val('');
          verifyCode.refresh();
          common.enable($loginBtn);
        } else {
          $("#code").hide();
          $("#md5password").val(md5($("#password").val()));
          common.clickSubmit($loginForm);
        }
      }
    });

    /*回车登陆*/
    $(document).keydown(function (e) {
      if (!e)
        e = e || window.event;
      if ((e.keyCode || e.which) === 13) {
        $loginBtn.click();
      }
    });

    /*???*/
    var msg = "<%=session.getAttribute("msg") %>";
    if (msg != "null" && msg.length > 0) {
      alert(msg);
      <%session.removeAttribute("msg");%>
    }
  });
});

requirejs.onError = function (err) {
  console.error(err);
  if (err.requireType === 'timeout') {
    console.error('modules: ' + err.requireModules);
  }
  throw err;
};
</script>
</body>
</html>